﻿using DoNet.Core;
using DoNet.System.IRepositories;
using DoNet.System.Models;

namespace DoNet.System.Repositories
{
    /// <summary>
    /// 应用仓储实现
    /// </summary>
    public class AppRepository : BaseRepository<App>, IAppRepository
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="config"></param>
        /// <param name="serviceProvider"></param>
        /// <param name="_logger"></param>
        /// <param name="_unitOfWork"></param>
        /// <param name="_httpContextAccessor"></param>
        public AppRepository(IServiceProvider serviceProvider) : base(serviceProvider)
        { }

        #region 同步方法
        /// <summary>
        /// 获取app对象
        /// </summary>
        /// <param name="appid">应用ID</param>
        /// <returns></returns>
        public App GetApp(string appid)
        {
            return Db.Queryable<App>().First(x => x.AppId == appid);
        }
        /// <summary>
        /// 获取app对象
        /// </summary>
        /// <param name="appid">应用ID</param>
        /// <param name="secret">应用密钥AppSecret</param>
        /// <returns></returns>
        public App GetApp(string appid, string secret)
        {
            return Db.Queryable<App>().First(x => x.AppId == appid && x.AppSecret == secret && x.EnabledMark == true);
        }
        #endregion 同步方法

        #region 异步方法
        /// <summary>
        /// 获取app对象
        /// </summary>
        /// <param name="appid">应用ID</param>
        /// <param name="secret">应用密钥AppSecret</param>
        /// <returns></returns>
        public async Task<App> GetAppAsync(string appid)
        {
            return await Db.Queryable<App>().FirstAsync(x => x.AppId == appid);
        }
        /// <summary>
        /// 获取app对象
        /// </summary>
        /// <param name="appid">应用ID</param>
        /// <returns></returns>
        public async Task<App> GetAppAsync(string appid, string secret)
        {
            return await Db.Queryable<App>().FirstAsync(x => x.AppId == appid && x.AppSecret == secret && x.EnabledMark == true);
        }
        #endregion 异步方法
    }
}
